﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UI
{
    public class CellMover
    {
        public static CellContainer CellContainer { get; set; }

        public static void Init(Cell cell)
        {
            bool Dragging = false;
            Point DragStart = Point.Empty;

            
            cell.DragPanel.MouseDown += delegate(object sender, MouseEventArgs e)
            {
                Dragging = true;
                DragStart = new Point(e.X, e.Y);
                cell.DragPanel.Capture = true;
            };

            cell.DragPanel.MouseUp += delegate(object sender, MouseEventArgs e)
            {
                Dragging = false;
                cell.DragPanel.Capture = false;
            };

            cell.DragPanel.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                if (Dragging)
                {
                    cell.Left = Math.Max(0, e.X + cell.Left - DragStart.X);
                    cell.Top = Math.Max(0, e.Y + cell.Top - DragStart.Y);
                }
            };
        }
    }
}
